﻿<EpiDashboard:GadgetBase x:Class="EpiDashboard.Gadgets.Charting.ParetoChartGadget"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:EpiDashboard="clr-namespace:EpiDashboard"
             xmlns:Controls="clr-namespace:EpiDashboard.Controls"
             xmlns:charting="clr-namespace:ComponentArt.Win.DataVisualization.Charting;assembly=ComponentArt.Win.DataVisualization.Charting"
             mc:Ignorable="d" 
             d:DesignHeight="700" d:DesignWidth="600"
                         SnapsToDevicePixels="True"
             Style="{DynamicResource gadgetBaseStyle}">
    <EpiDashboard:GadgetBase.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../ResourceDictionary.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </EpiDashboard:GadgetBase.Resources>
    <Grid>
        <Border Name="borderAll" Style="{DynamicResource mainGadgetBorder}" Background="White" >
            <Border.ContextMenu>
                <ContextMenu x:Name="gadgetContextMenu">                    
                    <MenuItem x:Name="mnuSendDataToHTML" Header="Send to web browser" />
                    <MenuItem x:Name="mnuSaveChartAsImage" Header="Save chart as image..." Click="mnuSaveChartAsImage_Click" />
                    <MenuItem x:Name="mnuCopyChartImage" Header="Copy chart image to clipboard" Click="mnuCopyChartImage_Click" />
                    <MenuItem x:Name="mnuCopyChartData" Header="Copy chart data to clipboard" Click="mnuCopyChartData_Click" />
                    <Separator/>
                    <MenuItem x:Name="mnuSendToBack" Header="Send gadget to back"/>
                    <MenuItem x:Name="mnuClose" Header="Close this gadget"/>
                </ContextMenu>
            </Border.ContextMenu>

            <Grid x:Name="grdMain">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="1" />
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="1" />
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="1" />
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>

                <Controls:GadgetHeaderPanel x:Name="headerPanel" Grid.Row="0" Text="Pareto Chart" />
                <Controls:GadgetMessagePanel Margin="4" x:Name="messagePanel" Grid.Row="2" Text="" />
                <Controls:GadgetDescriptionPanel Grid.Row="4" PanelMode="Collapsed" x:Name="descriptionPanel"></Controls:GadgetDescriptionPanel>

                <Controls:GadgetInfoPanel Grid.Row="4" Visibility="Collapsed" Margin="4" x:Name="infoPanel"></Controls:GadgetInfoPanel>
                <StackPanel Grid.Row="7" x:Name="panelMain" HorizontalAlignment="Left" VerticalAlignment="Top">
                    <Grid x:Name="gridChartLayoutRoot">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>

                        <TextBlock x:Name="tblockChartTitle" Grid.Row="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" FontSize="16" FontWeight="Bold" Margin="0, 6, 0, 6" Visibility="Collapsed" />

                        <Canvas x:Name="yAxisLabelCanvas" Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="25" Height="Auto" Margin="6, 0, -20, 0" >
                            <TextBlock x:Name="tblockYAxisLabel" FontWeight="DemiBold" Canvas.Bottom="0" Canvas.Left="0" TextAlignment="Center" Margin="0,0,0,-20" Text="Count" Visibility="Collapsed" >                    
                                <TextBlock.RenderTransform>
                                    <TransformGroup>                                
                                        <RotateTransform x:Name="rotate" Angle="270" />
                                    </TransformGroup>
                                </TextBlock.RenderTransform>
                            </TextBlock>
                        </Canvas>

                        <TextBlock x:Name="tblockXAxisLabel" FontWeight="DemiBold" Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Center" Margin="0, 0, 0, 6" Visibility="Collapsed" />

                        <charting:XYChart x:Name="xyChart" Background="White" DefaultGridLinesVisible="True" DefaultStripesVisible="True" DefaultCoordinateSystemFrameVisible="True" XPath="X" Grid.Row="0" Grid.Column="1" DataStructureCreated="xyChart_DataStructureCreated">
                            <charting:XYChart.XAxisArea>
                                <charting:AxisCoordinates x:Name="xAxisCoordinates" Angle="0">
                                    <!--<charting:NumericCoordinates />-->
                                    <!-- Change this to match your XAxis coordinate-type -->
                                </charting:AxisCoordinates>
                            </charting:XYChart.XAxisArea>

                            <charting:XYChart.Y2AxisArea>
                                <charting:AxisCoordinates x:Name="y2AxisCoordinates" AxisId="PercentAxis" />
                            </charting:XYChart.Y2AxisArea>
                            <charting:XYChart.Axes>
                                <charting:Axis Id="YAxis" x:Name="yAxis" UseReferenceValue="False" />
                                <charting:Axis Id="PercentAxis" x:Name="y2Axis" MinValue="0" MaxValue="100" UseReferenceValue="False" />
                            </charting:XYChart.Axes>
                            <charting:BarSeries x:Name="series0" Id="S0" YPath="Y" ShowPointAnnotations="True" BarKind="Rectangle" />
                            <charting:LineSeries x:Name="series1" Id="S1" Label="Percent" YAxisId="PercentAxis" YPath="Z" Marker="Diamond" Color="#FFfbc901" MarkerFill="Black" MarkerStrokeThickness="2" />
                            <!--<charting:OHLCSeries x:Name="series1" OpenPath="Open" LowPath="Lo" HighPath="Hi" ClosePath="Close"/>-->
                        </charting:XYChart>
                    </Grid>
                </StackPanel>
                <Controls:GadgetWaitPanel x:Name="waitPanel" Visibility="Collapsed" Grid.Row="1" Grid.RowSpan="6" Style="{StaticResource gadgetWaitPanelStyle}" />

                <StackPanel Grid.Row="1" Grid.RowSpan="7" Margin="00,-15,-10,0"  HorizontalAlignment="Right" VerticalAlignment="Top" >
                    <Grid x:Name="ConfigGrid" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,15,10,0" >
                        <Rectangle Style="{DynamicResource rectangleConfigOuter}" />
                        <Rectangle Style="{DynamicResource rectangleConfigInner}" />

                        <Path x:Name="pathTriangle" 
                              Margin="0,-2,90,0"
                              Data="M 5 0 L 10 10 0 10 Z" Fill="{DynamicResource gadgetBackgroundBrush}" IsHitTestVisible="False" HorizontalAlignment="Right" VerticalAlignment="Top" Height="7" />

                        <StackPanel Orientation="Vertical" Margin="25, 10, 25, 25" HorizontalAlignment="Center" VerticalAlignment="Top" >
                            <!--<TextBlock x:Name="ConfigExpandedTitle" HorizontalAlignment="Center" TextAlignment="Center" Text="Settings" Margin="5" FontSize="13" FontWeight="Bold" />-->
                            <TextBlock x:Name="tblockMainVariable" HorizontalAlignment="Left" TextAlignment="Center" Text="Main variable:" Margin="0,5,0,0"  />
                            <ComboBox x:Name="cmbField" Width="140" HorizontalAlignment="Left" SelectedIndex="0" />

                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition></ColumnDefinition>
                                    <ColumnDefinition Width="5"></ColumnDefinition>
                                    <ColumnDefinition></ColumnDefinition>
                                </Grid.ColumnDefinitions>
                                <StackPanel Grid.Column="0">
                                    <TextBlock x:Name="tblockWidth" HorizontalAlignment="Left" TextAlignment="Center" Text="Width:" Margin="0,5,0,0"  />
                                    <TextBox x:Name="txtWidth" Text="800" />
                                </StackPanel>

                                <StackPanel Grid.Column="2">
                                    <TextBlock x:Name="tblockHeight" HorizontalAlignment="Left" TextAlignment="Center" Text="Height:" Margin="0,5,0,0"  />
                                    <TextBox x:Name="txtHeight" Text="500" />
                                </StackPanel>
                            </Grid>

                            <Expander Margin="0, 5, 0, 0" x:Name="expanderAdvancedOptions">
                                <Expander.Header>
                                    <TextBlock>Advanced options</TextBlock>
                                </Expander.Header>
                                <Border Style="{StaticResource configGroupBorderStyle}">
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition></ColumnDefinition>
                                            <ColumnDefinition Width="15"></ColumnDefinition>
                                            <ColumnDefinition></ColumnDefinition>
                                        </Grid.ColumnDefinitions>

                                        <StackPanel x:Name="panelAdvanced1" Visibility="Visible">
                                            <TextBlock x:Name="tblockWeightVariable" HorizontalAlignment="Left" TextAlignment="Center" Text="Weight:" Margin="0,5,0,0"  />
                                            <ComboBox x:Name="cmbFieldWeight" Width="140" HorizontalAlignment="Left" SelectedIndex="0" />
                                        </StackPanel>

                                        <StackPanel Grid.Column="2" x:Name="panelAdvanced2" Visibility="Visible">
                                            <CheckBox x:Name="checkboxCommentLegalLabels" Margin="0,5,0,0" Content="Display list labels"  HorizontalAlignment="Left" IsEnabled="false"/>
                                            <CheckBox x:Name="checkboxIncludeMissing" Margin="0,5,0,0" Content="Include missing values" HorizontalAlignment="Left" IsChecked="False" />
                                            <!--<CheckBox x:Name="checkboxConfBars" Margin="0,5,0,0" Content="Show confidence intervals" HorizontalAlignment="Left" IsChecked="False" />-->
                                        </StackPanel>
                                    </Grid>
                                </Border>
                            </Expander>

                            <Expander Margin="0, 5, 0, 0" x:Name="expanderDisplayOptions">
                                <Expander.Header>
                                    <TextBlock>Display options</TextBlock>
                                </Expander.Header>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition></ColumnDefinition>
                                        <ColumnDefinition Width="15"></ColumnDefinition>
                                        <ColumnDefinition></ColumnDefinition>
                                        <ColumnDefinition Width="15"></ColumnDefinition>
                                        <ColumnDefinition></ColumnDefinition>
                                    </Grid.ColumnDefinitions>

                                    <Border Style="{StaticResource configGroupBorderStyle}" Grid.Column="0">
                                        <StackPanel Grid.Column="0">
                                            <Label x:Name="lblColorsStyles" FontWeight="Bold">Colors and styles</Label>
                                            <CheckBox x:Name="checkboxUseRefValues" Margin="0,5,0,0" Content="Use reference values" HorizontalAlignment="Left" IsChecked="True" Checked="checkboxUseRefValues_Checked" Unchecked="checkboxUseRefValues_Unchecked" />
                                            <CheckBox x:Name="checkboxAnnotations" Margin="0,5,0,0" Content="Show annotations" HorizontalAlignment="Left" IsChecked="False" />

                                            <TextBlock x:Name="tblockBarSpacing" HorizontalAlignment="Left" TextAlignment="Center" Text="Space between bars:" Margin="0,5,0,0"  />
                                            <ComboBox x:Name="cmbBarSpacing" Width="140" HorizontalAlignment="Left" SelectedIndex="0" SelectionChanged="cmbBarSpacing_SelectionChanged">
                                                <ComboBox.Items>
                                                    <ComboBoxItem>Default</ComboBoxItem>
                                                    <ComboBoxItem>None</ComboBoxItem>
                                                    <ComboBoxItem>Small</ComboBoxItem>
                                                    <ComboBoxItem>Medium</ComboBoxItem>
                                                    <ComboBoxItem>Large</ComboBoxItem>
                                                </ComboBox.Items>
                                            </ComboBox>

                                            <TextBlock x:Name="tblockPalette" HorizontalAlignment="Left" TextAlignment="Center" Text="Color palette:" Margin="0,5,0,0"  />
                                            <ComboBox x:Name="cmbPalette" Width="140" HorizontalAlignment="Left" SelectedIndex="12" SelectionChanged="cmbPalette_SelectionChanged">
                                                <ComboBox.Items>
                                                    <ComboBoxItem>Atlantic</ComboBoxItem>
                                                    <ComboBoxItem>Breeze</ComboBoxItem>
                                                    <ComboBoxItem>ComponentArt</ComboBoxItem>
                                                    <ComboBoxItem>Deep</ComboBoxItem>
                                                    <ComboBoxItem>Earth</ComboBoxItem>
                                                    <ComboBoxItem>Evergreen</ComboBoxItem>
                                                    <ComboBoxItem>Heatwave</ComboBoxItem>
                                                    <ComboBoxItem>Montreal</ComboBoxItem>
                                                    <ComboBoxItem>Pastel</ComboBoxItem>
                                                    <ComboBoxItem>Renaissance</ComboBoxItem>
                                                    <ComboBoxItem>SharePoint</ComboBoxItem>
                                                    <ComboBoxItem>Study</ComboBoxItem>
                                                    <ComboBoxItem>VibrantA</ComboBoxItem>
                                                    <ComboBoxItem>VibrantB</ComboBoxItem>
                                                    <ComboBoxItem>VibrantC</ComboBoxItem>
                                                </ComboBox.Items>
                                            </ComboBox>

                                            <TextBlock x:Name="tblockBarType" HorizontalAlignment="Left" TextAlignment="Center" Text="Bar type:" Margin="0,5,0,0"  />
                                            <ComboBox x:Name="cmbBarType" Width="140" HorizontalAlignment="Left" SelectedIndex="2" SelectionChanged="cmbBarType_SelectionChanged">
                                                <ComboBox.Items>
                                                    <ComboBoxItem>Block</ComboBoxItem>
                                                    <ComboBoxItem>Cylinder</ComboBoxItem>
                                                    <ComboBoxItem>Rectangle</ComboBoxItem>
                                                    <ComboBoxItem>RoundedBlock</ComboBoxItem>
                                                </ComboBox.Items>
                                            </ComboBox>
                                        </StackPanel>
                                    </Border>

                                    <Border Style="{StaticResource configGroupBorderStyle}" Grid.Column="2">
                                        <StackPanel Grid.Column="2">
                                            <Label x:Name="lblLabels" FontWeight="Bold">Labels</Label>
                                            <TextBlock x:Name="tblockYAxisLabelValue" HorizontalAlignment="Left" TextAlignment="Center" Text="Y-axis label:" Margin="0,5,0,0"  />
                                            <TextBox x:Name="txtYAxisLabelValue" HorizontalAlignment="Stretch" Text="Count" />

                                            <TextBlock x:Name="tblockXAxisLabelType" HorizontalAlignment="Left" TextAlignment="Center" Text="X-axis label type:" Margin="0,5,0,0"  />
                                            <ComboBox x:Name="cmbXAxisLabelType" Width="140" HorizontalAlignment="Left" SelectedIndex="0" SelectionChanged="cmbXAxisLabelType_SelectionChanged">
                                                <ComboBox.Items>
                                                    <ComboBoxItem>Automatic</ComboBoxItem>
                                                    <ComboBoxItem>Field Prompt</ComboBoxItem>
                                                    <ComboBoxItem>None</ComboBoxItem>
                                                    <ComboBoxItem>Custom</ComboBoxItem>
                                                </ComboBox.Items>
                                            </ComboBox>

                                            <TextBlock x:Name="tblockXAxisLabelValue" HorizontalAlignment="Left" TextAlignment="Center" Text="X-axis label:" Margin="0,5,0,0" />
                                            <TextBox x:Name="txtXAxisLabelValue" HorizontalAlignment="Stretch" Text="" IsEnabled="False" />

                                            <TextBlock x:Name="tblockXAxisAngle" HorizontalAlignment="Left" TextAlignment="Center" Text="X-axis angle:" Margin="0,5,0,0"  />
                                            <TextBox x:Name="txtXAxisAngle" HorizontalAlignment="Stretch" Text="0" />

                                            <TextBlock x:Name="tblockChartTitleValue" HorizontalAlignment="Left" TextAlignment="Center" Text="Chart title:" Margin="0,5,0,0"  />
                                            <TextBox x:Name="txtChartTitle" AcceptsReturn="True" TextWrapping="Wrap" HorizontalAlignment="Stretch" />
                                        </StackPanel>
                                    </Border>

                                    <Border Style="{StaticResource configGroupBorderStyle}" Grid.Column="4">
                                        <StackPanel Grid.Column="0">
                                            <Label x:Name="lblLegend" FontWeight="Bold">Legend</Label>
                                            <CheckBox x:Name="checkboxShowLegend" Margin="0,5,0,0" Content="Show legend" HorizontalAlignment="Left" IsChecked="False" Checked="checkboxShowLegend_Checked" Unchecked="checkboxShowLegend_Unchecked" />
                                            <CheckBox x:Name="checkboxShowLegendBorder" Margin="0,5,0,0" Content="Show legend border" HorizontalAlignment="Left" IsChecked="False" Checked="checkboxShowLegendBorder_Checked" Unchecked="checkboxShowLegendBorder_Unchecked" />
                                            <CheckBox x:Name="checkboxShowVarName" Margin="0,5,0,0" Content="Show variable names" HorizontalAlignment="Left" IsChecked="False" />

                                            <TextBlock x:Name="tblockLegendFontSize" HorizontalAlignment="Left" TextAlignment="Center" Text="Legend font size:" Margin="0,5,0,0"  />
                                            <TextBox x:Name="txtLegendFontSize" HorizontalAlignment="Stretch" Text="12" />

                                            <!--<TextBlock x:Name="tblockLegendFontFamily" HorizontalAlignment="Left" TextAlignment="Center" Text="Legend font family:" Margin="0,5,0,0" />
                                            <ComboBox Width="140" x:Name="cmbFontSelector" HorizontalAlignment="Left" SelectionChanged="cmbFontSelector_SelectionChanged">
                                                <ComboBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <TextBlock Text="{Binding}" FontFamily="{Binding}"/>
                                                    </DataTemplate>
                                                </ComboBox.ItemTemplate>
                                            </ComboBox>-->
                                        </StackPanel>
                                    </Border>
                                </Grid>
                            </Expander>
                            <Button x:Name="btnRun" Content="Run" Margin="0,20,0,0" Click="btnRun_Click" />
                        </StackPanel>
                    </Grid>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</EpiDashboard:GadgetBase>
